package April._23.work4;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

public class Main {
    public static void main(String[] args) {
        FileOutputStream out;
        try {
             out = new FileOutputStream(new File("fileTest\\time.txt"));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        MyCallable myCallable = new MyCallable(new File("fileTest\\a.txt"), new File("fileTest\\b.txt"));
        FutureTask<String> task1 = new FutureTask<>(myCallable);
        new Thread(task1).start();
        try {
            String s1=task1.get();
            out.write(s1.getBytes());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        FutureTask<String> task2 = new FutureTask<>(new MyCallable(new File("fileTest\\a.txt"), new File("fileTest\\noun.txt")));
        FutureTask<String> task3 = new FutureTask<>(new MyCallable(new File("fileTest\\a.txt"), new File("fileTest\\verb.txt")));
        new Thread(task2).start();
        String s2= null;
        try {
            s2 = task2.get();
            out.write(s2.getBytes());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        new Thread(task3).start();
        String s3= null;
        try {
            s3 = task3.get();
            out.write(s3.getBytes());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
